<?php

/**
 * 模块：搜索
 * @copyright (C)2011 Cenwor Inc.
 * @author Moyo <dev@uuland.org>
 * @package module
 * @name search.mod.php
 * @version 1.0
 */

class ModuleObject extends MasterObject
{

    function ModuleObject( $config )
    {
        $this->MasterObject($config);
        $runCode = Load::moduleCode($this);
        $this->$runCode();
    }
    function Main(){
    	$this->Title = $this->get_kw("kw");
    	$data = logic('product')->display();
    	$product = $data['product'];
    	include handler('template')->file('catalog');
    }
    
    function Ajax()
    {
        $fid = get('fid', 'txt');
        $wd = get('wd', 'txt');
        $result = logic('isearcher')->Search($fid, $wd);
        exit(jsonEncode($result));
    }
    
    private function get_kw($key = 'kw', $filter_rule = '/[\~\!\@\#\$\%\^\&\*\(\)\_\+\`\-\=\{\}\:\"\|\<\>\?\[\]\;\\\'\\\\\,\/]/')
    {
    	$kw = get($key, 'string');
    	if ($filter_rule)
    	{
    		$kw = preg_replace($filter_rule, '', $kw);
    	}
    	$ku = ENC_G2U($kw);
    	$kg = ENC_U2G($kw);
    	if ($kw == $ku)
    	{
    		$ic = 'utf8';
    	}
    	elseif ($kw == $kg)
    	{
    		$ic = 'gbk';
    	}
    	if (ENC_IS_GBK)
    	{
    		if ($ic == 'utf8')
    		{
    			$kw = $kg;
    		}
    	}
    	else
    	{
    		if ($ic == 'gbk')
    		{
    			$kw = $ku;
    		}
    	}
    	return $kw;
    }
}

?>